using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BizTalkCrossReferenceManager.UI
{
    /// <summary>
    /// Form for managing xref common values
    /// </summary>
    public partial class IDXRefCommonValuesForm : Form
    {
        private int _XRefID;

        /// <summary>
        /// Ctor
        /// </summary>
        public IDXRefCommonValuesForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Form load event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IDXRefCommonValuesForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'crossReferenceDataDataSet.xref_IDXRef' table. You can move, or remove it, as needed.
            this.xref_IDXRefTableAdapter.Fill(this.crossReferenceDataDataSet.xref_IDXRef);
            QueryButton_Click(this, null);
        }
        /// <summary>
        /// Form closing event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IDXRefCommonValuesForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveChanges();
        }
        /// <summary>
        /// Query click event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QueryButton_Click(object sender, EventArgs e)
        {
            SaveChanges();
            this._XRefID = (int)XRefTypeComboBox.SelectedValue;            
            this.xref_IDXRefCommonValuesTableAdapter.FillByXRefTypeId(this.crossReferenceDataDataSet.xref_IDXRefCommonValues, this._XRefID);           
        }
        /// <summary>
        /// Saves the info in the dataset back to the database
        /// </summary>
        private void SaveChanges()
        {
            if (this.crossReferenceDataDataSet.xref_IDXRefCommonValues.GetChanges() != null)
            {
                DialogResult dr = MessageBox.Show("Would you like to save the changes", "Save Changes", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    this.xref_IDXRefCommonValuesTableAdapter.Update(this.crossReferenceDataDataSet);
                }
            }
        }
        
        private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {
            
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {            
            this.dataGridView1.Rows[e.RowIndex].Cells["idXRefID"].Value = this._XRefID;            
        }                   
    }
}